<?php


namespace App\Shuixing\Controllers;


use App\Models\WxNavigation;
use App\Models\WxNavigationPlate;

class ToolController
{
    public function index($id)
    {

        View()->composer('shuixing/home', function ($view) use ($id) {
            $view->with(['menu' => 5, 'linav' => $id]);
        });

        if ($id == 0) {//全部工具利器导航
            $data = WxNavigationPlate::where('type', 1)
                ->where('state', 0)
                ->orderBy('sort', 'asc')
                ->get(['id', 'name', 'introduce']);
            $data->map(function ($v) {
                $v->list = WxNavigation::where('type', 1)
                    ->where('state', 0)
                    ->where('np_id', $v->id)
                    ->get();
            });
        } else {
            $data = WxNavigationPlate::where('type', 1)
                ->where('state', 0)
                ->where('id', $id)
                ->orderBy('sort', 'asc')
                ->get(['id', 'name', 'introduce']);
            $data->map(function ($v) {
                $v->list = WxNavigation::where('type', 1)
                    ->where('state', 0)
                    ->where('np_id', $v->id)
                    ->get();
            });
        }

        return view('shuixing/tool', ['data' => $data]);
    }
}
